package com.example.work_01;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.util.Timer;
import java.util.TimerTask;

public class FrameLayout extends AppCompatActivity {
    private ImageView image;
    private int num=0;
    private int SIGN=10;
    Handler handler;
    Timer timer=new Timer();
    private int[] images={R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4,R.drawable.img5};
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.framelayout);
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if(msg.what==SIGN){
                    if (num>=images.length){
                        num=0;
                    }
                    image.setImageResource(images[num++]);

                }

            }
        };
        image=(ImageView) findViewById(R.id.image01);
        timer.schedule(task,1000,1000);
        Button bn4=(Button) findViewById(R.id.bn4);
        bn4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(FrameLayout.this,MainActivity.class);
                startActivity(intent);
            }
        });


    }
    TimerTask task =new TimerTask() {
        @Override
        public void run() {
            Message msg = new Message();
            msg.what = SIGN;
            handler.sendMessage(msg);

        }
    };
}
